package top.wshape1.shiziapi.common.utils;

import com.alibaba.fastjson2.JSON;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-08-26
 */

public class Base64Util {

    public static String encode(String rawString) {
        return new String(Base64.getEncoder().encode(rawString.getBytes(StandardCharsets.UTF_8)));
    }

    public static String decode(String base64String) {
        return new String(Base64.getDecoder().decode(base64String));
    }

    public static <T> T decodeAndParse(String base64String, Class<T> clazz) {
        String decode = Base64Util.decode(base64String);
        return JSON.parseObject(decode, clazz);
    }

}
